﻿using System;
using System.IO;
using System.Text;

// Token: 0x02000532 RID: 1330
public class WaveHeader
{
	// Token: 0x17000405 RID: 1029
	// (get) Token: 0x060021DA RID: 8666 RVA: 0x000CE000 File Offset: 0x000CC200
	// (set) Token: 0x060021DB RID: 8667 RVA: 0x000CE008 File Offset: 0x000CC208
	public int FileSize { get; private set; }

	// Token: 0x17000406 RID: 1030
	// (get) Token: 0x060021DC RID: 8668 RVA: 0x000CE014 File Offset: 0x000CC214
	// (set) Token: 0x060021DD RID: 8669 RVA: 0x000CE01C File Offset: 0x000CC21C
	public string RIFF { get; private set; }

	// Token: 0x17000407 RID: 1031
	// (get) Token: 0x060021DE RID: 8670 RVA: 0x000CE028 File Offset: 0x000CC228
	// (set) Token: 0x060021DF RID: 8671 RVA: 0x000CE030 File Offset: 0x000CC230
	public int Size { get; private set; }

	// Token: 0x17000408 RID: 1032
	// (get) Token: 0x060021E0 RID: 8672 RVA: 0x000CE03C File Offset: 0x000CC23C
	// (set) Token: 0x060021E1 RID: 8673 RVA: 0x000CE044 File Offset: 0x000CC244
	public string WAVE { get; private set; }

	// Token: 0x17000409 RID: 1033
	// (get) Token: 0x060021E2 RID: 8674 RVA: 0x000CE050 File Offset: 0x000CC250
	// (set) Token: 0x060021E3 RID: 8675 RVA: 0x000CE058 File Offset: 0x000CC258
	public string FMT { get; private set; }

	// Token: 0x1700040A RID: 1034
	// (get) Token: 0x060021E4 RID: 8676 RVA: 0x000CE064 File Offset: 0x000CC264
	// (set) Token: 0x060021E5 RID: 8677 RVA: 0x000CE06C File Offset: 0x000CC26C
	public int FmtChunkSize { get; private set; }

	// Token: 0x1700040B RID: 1035
	// (get) Token: 0x060021E6 RID: 8678 RVA: 0x000CE078 File Offset: 0x000CC278
	// (set) Token: 0x060021E7 RID: 8679 RVA: 0x000CE080 File Offset: 0x000CC280
	public short FormatId { get; private set; }

	// Token: 0x1700040C RID: 1036
	// (get) Token: 0x060021E8 RID: 8680 RVA: 0x000CE08C File Offset: 0x000CC28C
	// (set) Token: 0x060021E9 RID: 8681 RVA: 0x000CE094 File Offset: 0x000CC294
	public short Channels { get; private set; }

	// Token: 0x1700040D RID: 1037
	// (get) Token: 0x060021EA RID: 8682 RVA: 0x000CE0A0 File Offset: 0x000CC2A0
	// (set) Token: 0x060021EB RID: 8683 RVA: 0x000CE0A8 File Offset: 0x000CC2A8
	public int Frequency { get; private set; }

	// Token: 0x1700040E RID: 1038
	// (get) Token: 0x060021EC RID: 8684 RVA: 0x000CE0B4 File Offset: 0x000CC2B4
	// (set) Token: 0x060021ED RID: 8685 RVA: 0x000CE0BC File Offset: 0x000CC2BC
	public int DataSpeed { get; private set; }

	// Token: 0x1700040F RID: 1039
	// (get) Token: 0x060021EE RID: 8686 RVA: 0x000CE0C8 File Offset: 0x000CC2C8
	// (set) Token: 0x060021EF RID: 8687 RVA: 0x000CE0D0 File Offset: 0x000CC2D0
	public short BlockSize { get; private set; }

	// Token: 0x17000410 RID: 1040
	// (get) Token: 0x060021F0 RID: 8688 RVA: 0x000CE0DC File Offset: 0x000CC2DC
	// (set) Token: 0x060021F1 RID: 8689 RVA: 0x000CE0E4 File Offset: 0x000CC2E4
	public short BitPerSample { get; private set; }

	// Token: 0x17000411 RID: 1041
	// (get) Token: 0x060021F2 RID: 8690 RVA: 0x000CE0F0 File Offset: 0x000CC2F0
	// (set) Token: 0x060021F3 RID: 8691 RVA: 0x000CE0F8 File Offset: 0x000CC2F8
	public string DATA { get; private set; }

	// Token: 0x17000412 RID: 1042
	// (get) Token: 0x060021F4 RID: 8692 RVA: 0x000CE104 File Offset: 0x000CC304
	// (set) Token: 0x060021F5 RID: 8693 RVA: 0x000CE10C File Offset: 0x000CC30C
	public int TrueWavBufSize { get; private set; }

	// Token: 0x17000413 RID: 1043
	// (get) Token: 0x060021F6 RID: 8694 RVA: 0x000CE118 File Offset: 0x000CC318
	// (set) Token: 0x060021F7 RID: 8695 RVA: 0x000CE120 File Offset: 0x000CC320
	public int TrueWavBufIndex { get; private set; }

	// Token: 0x17000414 RID: 1044
	// (get) Token: 0x060021F8 RID: 8696 RVA: 0x000CE12C File Offset: 0x000CC32C
	// (set) Token: 0x060021F9 RID: 8697 RVA: 0x000CE134 File Offset: 0x000CC334
	public int TrueSamples { get; private set; }

	// Token: 0x060021FA RID: 8698 RVA: 0x000CE140 File Offset: 0x000CC340
	public static WaveHeader ReadWaveHeader(string path)
	{
		WaveHeader result;
		using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
		{
			result = WaveHeader.ReadWaveHeader(fileStream);
		}
		return result;
	}

	// Token: 0x060021FB RID: 8699 RVA: 0x000CE184 File Offset: 0x000CC384
	public static WaveHeader ReadWaveHeader(Stream stream)
	{
		if (stream == null)
		{
			return null;
		}
		WaveHeader result;
		using (BinaryReader binaryReader = new BinaryReader(stream))
		{
			result = WaveHeader.ReadWaveHeader(binaryReader);
		}
		return result;
	}

	// Token: 0x060021FC RID: 8700 RVA: 0x000CE1CC File Offset: 0x000CC3CC
	public static WaveHeader ReadWaveHeader(BinaryReader reader)
	{
		WaveHeader waveHeader = new WaveHeader();
		waveHeader.RIFF = Encoding.ASCII.GetString(reader.ReadBytes(4));
		waveHeader.Size = reader.ReadInt32();
		waveHeader.WAVE = Encoding.ASCII.GetString(reader.ReadBytes(4));
		if (waveHeader.RIFF.ToUpper() != "RIFF" || waveHeader.WAVE.ToUpper() != "WAVE")
		{
			return null;
		}
		while (waveHeader.FMT == null || waveHeader.FMT.ToLower() != "fmt")
		{
			waveHeader.FMT = Encoding.ASCII.GetString(reader.ReadBytes(4));
			if (waveHeader.FMT.ToLower().Trim() == "fmt")
			{
				break;
			}
			uint num = reader.ReadUInt32();
			reader.BaseStream.Seek((long)((ulong)num), SeekOrigin.Current);
		}
		waveHeader.FmtChunkSize = reader.ReadInt32();
		waveHeader.FormatId = reader.ReadInt16();
		waveHeader.Channels = reader.ReadInt16();
		waveHeader.Frequency = reader.ReadInt32();
		waveHeader.DataSpeed = reader.ReadInt32();
		waveHeader.BlockSize = reader.ReadInt16();
		waveHeader.BitPerSample = reader.ReadInt16();
		reader.BaseStream.Seek((long)(waveHeader.FmtChunkSize - 16), SeekOrigin.Current);
		while (waveHeader.DATA == null || waveHeader.DATA.ToLower() != "data")
		{
			waveHeader.DATA = Encoding.ASCII.GetString(reader.ReadBytes(4));
			if (waveHeader.DATA.ToLower() == "data")
			{
				break;
			}
			uint num2 = reader.ReadUInt32();
			reader.BaseStream.Seek((long)((ulong)num2), SeekOrigin.Current);
		}
		waveHeader.TrueWavBufSize = reader.ReadInt32();
		waveHeader.TrueSamples = waveHeader.TrueWavBufSize / (int)(waveHeader.BitPerSample / 8) / (int)waveHeader.Channels;
		waveHeader.TrueWavBufIndex = (int)reader.BaseStream.Position;
		reader.BaseStream.Seek(0L, SeekOrigin.Begin);
		return waveHeader;
	}
}
